package address

import (
	"gitee.com/xgotool/backend-framework-template/config"
	"gitee.com/xgotool/backend-framework-template/model"
	"gitee.com/xiaoyutab/xgotool/xnum"
)

// 获取地址的标签列表信息
//
//	uid	用户ID
func TagList(uid uint) []string {
	if uid == 0 {
		return model.AddressTagDefault
	}
	mod := model.Address{}
	// 获取数据库连接
	conn, err := config.GetConnect()
	if err != nil {
		return model.AddressTagDefault
	}
	tag_name := []string{}
	err = conn.Table(mod.TableName()).Where("uid", uid).Where("is_deleted", 0).Pluck("tag_name", &tag_name).Error
	if err != nil {
		return model.AddressTagDefault
	}
	for _, v := range model.AddressTagDefault {
		if !xnum.InArray(v, tag_name) {
			tag_name = append(tag_name, v)
		}
	}
	return tag_name
}
